How to explain N in varchar (N) and nvarchar (n: Nvarchar (n) can store up to nCharacter, Does not distinguish between Chinese and English. Varchar (n) can store up to n Bytes, A Chinese character is two bytes.
Space occupied:A single nvarchar (n)
This article describes in detail the performance and space occupied by varchar (n) and nvarchar (n) in SQL. For more information, see.
This article describes in detail the performance and space occupied by varchar (n) and nvarchar (n) in SQL. For
Ext.: http://blog.csdn.net/jackychu/article/details/4183118Http://www.cnblogs.com/jhxk/articles/1633578.htmlMany developers in the database design often do not have much to consider char, varchar type, some do not pay attention to, because the
Now excerpt the explanations for these data types in sql2005 Books Online
Character data types (nchar length fixed, nvarchar length variable), and Unicode data use the Unicode UCS-2 character set.
nchar [(N)]
N-Character fixed-length Unicode
The char type in the database is used to store fixed-length strings. The efficiency is slightly higher than that of varchar. However, it consumes more space than varchar. For example, if you store the string "ABC", for char (20), it means that the
nchar, or variable-length, nvarchar, Unicode data and use the UNICODE UCS-2 character set."> Nvarchar [(N |Max)]
Variable-length Unicode string data. n defines the string length and can be a value from 1 through 4,000."> n defines the string
In SQL Server, when we set character fields, there are often a number of data types for us to choose from, such as: char nchar varchar nvarchar, then we should choose which one? Here's a Yi Yilai description of the difference.
char: fixed length,
1.charThe length of char is fixed, for example, you define char (20), even if you insert ABC, less than 20 bytes, the database will automatically add 17 spaces after ABC to complement 20 bytes;Char is a distinction between English and Chinese, which
The string "abc", for Char (20), means that the characters you store will account for 20 bytes (including 17 null characters), while the same VARCHAR2 (20) occupies only 3 bytes of length, 20 is the maximum value, and when you store characters less
In SQL Server, when we set character fields, there are often many data types for us to choose from, such as char nchar varchar nvarchar. Which one should we choose? The differences are described one by one.
Char:Fixed Length, non-Unicode character
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.